home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / MetalworksFrame.java < prev    next >
Text File  |  1998-06-30  |  7KB  |  247 lines

  1. /*
  2.  * @(#)MetalworksFrame.java    1.9 98/04/13
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. import java.awt.*;
  22. import java.io.*;
  23. import java.awt.event.*;
  24. import java.beans.*;
  25. import com.sun.java.swing.*;
  26. import com.sun.java.swing.border.*;
  27. import com.sun.java.swing.preview.*;
  28.  
  29. import com.sun.java.swing.plaf.metal.*;
  30.  
  31.  
  32. /**
  33.   * This is the main container frame for the Metalworks demo app
  34.   *
  35.   * @version 1.9 04/13/98
  36.   * @author Steve Wilson
  37.   */
  38. public class MetalworksFrame extends JFrame {
  39.  
  40.     JMenuBar menuBar;
  41.     JDesktopPane desktop;
  42.     JInternalFrame toolPalette;
  43.     JCheckBoxMenuItem showToolPaletteMenuItem;
  44.  
  45.     static final Integer DOCLAYER = new Integer(5);
  46.     static final Integer TOOLLAYER = new Integer(6);
  47.     static final Integer HELPLAYER = new Integer(7);
  48.  
  49.     static final String ABOUTMSG = "Metalworks \n \nAn application written to show off the Java Look & Feel. \n \nWritten by the JavaSoft Look & Feel Team \n  Michael Albers\n  Tom Santos\n  Jeff Shapiro\n  Steve Wilson";
  50.  
  51.  
  52.     public MetalworksFrame() {
  53.         super("Metalworks");
  54.         final int inset = 50;
  55.         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  56.     setBounds ( inset, inset, screenSize.width - inset*2, screenSize.height - inset*2 );
  57.     buildContent();
  58.     buildMenus();
  59.     this.addWindowListener(new WindowAdapter() {
  60.                            public void windowClosing(WindowEvent e) {
  61.                    quit();
  62.                    }});
  63.     UIManager.addPropertyChangeListener(new UISwitchListener((JComponent)getRootPane()));
  64.     }
  65.  
  66.     protected void buildMenus() {
  67.         menuBar = new JMenuBar();
  68.     menuBar.setOpaque(true);
  69.     JMenu file = buildFileMenu();
  70.     JMenu edit = buildEditMenu();
  71.     JMenu views = buildViewsMenu();
  72.     JMenu help = buildHelpMenu();
  73.  
  74.     // load a theme from a text file
  75.     MetalTheme myTheme = null;
  76.     try {
  77.         myTheme =  new PropertiesMetalTheme(new FileInputStream("../MyTheme.theme"));
  78.     } catch (IOException e) {System.out.println(e);}
  79.  
  80.     // build an array of themes
  81.     MetalTheme[] themes = { new DefaultMetalTheme(),
  82.                 new GreenMetalTheme(),
  83.                 new AquaMetalTheme(),
  84.                 new KhakiMetalTheme(),
  85.                 new DemoMetalTheme(),
  86.                 new ContrastMetalTheme(),
  87.                 new BigContrastMetalTheme(),
  88.                             myTheme };
  89.  
  90.     // put the themes in a menu
  91.     JMenu themeMenu = new MetalThemeMenu("Theme", themes);
  92.  
  93.     menuBar.add(file);
  94.     menuBar.add(edit);
  95.     menuBar.add(views);
  96.     menuBar.add(themeMenu);
  97.     menuBar.add(help);
  98.     setJMenuBar(menuBar);    
  99.     }
  100.  
  101.     protected JMenu buildFileMenu() {
  102.     JMenu file = new JMenu("File");
  103.     JMenuItem newWin = new JMenuItem("New");
  104.     JMenuItem open = new JMenuItem("Open");
  105.     JMenuItem quit = new JMenuItem("Quit");
  106.  
  107.     newWin.addActionListener(new ActionListener() {
  108.                            public void actionPerformed(ActionEvent e) {
  109.                    newDocument();
  110.                    }});
  111.  
  112.     open.addActionListener(new ActionListener() {
  113.                            public void actionPerformed(ActionEvent e) {
  114.                    openDocument();
  115.                    }});
  116.  
  117.     quit.addActionListener(new ActionListener() {
  118.                            public void actionPerformed(ActionEvent e) {
  119.                    quit();
  120.                    }});
  121.  
  122.     file.add(newWin);
  123.     file.add(open);
  124.     file.add(new JSeparator());
  125.     file.add(quit);
  126.     return file;
  127.     }
  128.  
  129.     protected JMenu buildEditMenu() {
  130.     JMenu edit = new JMenu("Edit");
  131.     JMenuItem undo = new JMenuItem("Undo");
  132.     JMenuItem copy = new JMenuItem("Copy");
  133.     JMenuItem cut = new JMenuItem("Cut");
  134.     JMenuItem paste = new JMenuItem("Paste");
  135.     JMenuItem prefs = new JMenuItem("Preferences...");
  136.  
  137.     undo.setEnabled(false);
  138.     copy.setEnabled(false);
  139.     cut.setEnabled(false);
  140.     paste.setEnabled(false);
  141.  
  142.     prefs.addActionListener(new ActionListener() {
  143.                            public void actionPerformed(ActionEvent e) {
  144.                    openPrefsWindow();
  145.                    }});
  146.  
  147.     edit.add(undo);
  148.     edit.add(new JSeparator());
  149.     edit.add(cut);
  150.     edit.add(copy);
  151.     edit.add(paste);
  152.     edit.add(new JSeparator());
  153.     edit.add(prefs);
  154.     return edit;
  155.     }
  156.  
  157.     protected JMenu buildViewsMenu() {
  158.     JMenu views = new JMenu("Views");
  159.  
  160.     JMenuItem inBox = new JMenuItem("Open In-Box");
  161.     JMenuItem outBox = new JMenuItem("Open Out-Box");
  162.     outBox.setEnabled(false);
  163.  
  164.     inBox.addActionListener(new ActionListener() {
  165.                            public void actionPerformed(ActionEvent e) {
  166.                    openInBox();
  167.                    }});
  168.  
  169.     views.add(inBox);
  170.     views.add(outBox);
  171.     return views;
  172.     }
  173.  
  174.     protected JMenu buildHelpMenu() {
  175.     JMenu help = new JMenu("Help");
  176.         JMenuItem about = new JMenuItem("About Metalworks...");
  177.     JMenuItem openHelp = new JMenuItem("Open Help Window");
  178.  
  179.     about.addActionListener(new ActionListener() {
  180.         public void actionPerformed(ActionEvent e) {
  181.             showAboutBox();
  182.         }
  183.     });
  184.  
  185.     openHelp.addActionListener(new ActionListener() {
  186.                            public void actionPerformed(ActionEvent e) {
  187.                    openHelpWindow();
  188.                    }});
  189.  
  190.     help.add(about);
  191.     help.add(openHelp);
  192.  
  193.     return help;
  194.     }
  195.  
  196.     protected void buildContent() {
  197.         desktop = new JDesktopPane();
  198.         getContentPane().add(desktop);
  199.     }
  200.  
  201.     public void quit() {
  202.         System.exit(0);
  203.     }
  204.  
  205.     public void newDocument() {
  206.     JInternalFrame doc = new MetalworksDocumentFrame();
  207.     desktop.add(doc, DOCLAYER);
  208.     try { 
  209.         doc.setSelected(true); 
  210.     } catch (java.beans.PropertyVetoException e2) {}
  211.     }
  212.  
  213.     public void openDocument() {
  214.         JFileChooser chooser = new JFileChooser();
  215.     chooser.showOpenDialog(this);
  216.     }
  217.  
  218.     public void openHelpWindow() {
  219.     JInternalFrame help = new MetalworksHelp();
  220.     desktop.add(help, HELPLAYER);
  221.     try { 
  222.         help.setSelected(true); 
  223.     } catch (java.beans.PropertyVetoException e2) {}
  224.     }
  225.  
  226.     public void showAboutBox() {
  227.         JOptionPane.showMessageDialog(this, ABOUTMSG);
  228.     }
  229.  
  230.     public void openPrefsWindow() {
  231.         MetalworksPrefs dialog = new MetalworksPrefs(this);
  232.     dialog.show();
  233.  
  234.     }
  235.  
  236.     public void openInBox() {
  237.     JInternalFrame doc = new MetalworksInBox();
  238.     desktop.add(doc, DOCLAYER);
  239.     try { 
  240.         doc.setSelected(true); 
  241.     } catch (java.beans.PropertyVetoException e2) {}
  242.     }
  243.  
  244. }
  245.  
  246.  
  247.